import fs from "fs";
import path from "path";
import Koa from "koa";
import bodyParser from "koa-bodyparser";
import serve from "koa-static";
import cors from "koa2-cors";
import KoaLogger from "koa-logger";
import processRouter from "./routes/process";
import datasetRouter from "./routes/dataset";
import testRouter from "./routes/test";

const app = new Koa();

const corsObj = cors({
  origin: "*",
  maxAge: 5, //指定本次预检请求的有效期，单位为秒。
  credentials: true, //是否允许发送Cookie
  allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], //设置所允许的HTTP请求方法
  allowHeaders: ["Content-Type", "Authorization", "Accept"], //设置服务器支持的所有头信息字段
  exposeHeaders: ["WWW-Authenticate", "Server-Authorization"], //设置获取其他自定义字段
});

app.use(KoaLogger());
app.use(corsObj);
app.use(bodyParser());
app.use(processRouter.routes()).use(processRouter.allowedMethods());
app.use(datasetRouter.routes()).use(datasetRouter.allowedMethods());
app.use(testRouter.routes()).use(testRouter.allowedMethods());
app.use(serve("public"));

app.listen(3000, () => {
  console.log("http://localhost:3000");
});
